package com.education.user.mapper;


import com.education.user.pojo.SysAppUser;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author: ly
 * @create: 2018-07-05 15:55
 **/
@Repository
public interface SysAppUserMapper extends Mapper<SysAppUser> {

    /**
     *  进行关联查询 学校名 和 班级名
     */
    @Select({
            "<script>",
            "  SELECT " +
                    "sau.id, sau.sys_relname sysRelname, sau.sys_ico sysIco, sau.sys_state sysState, sau.sys_phone sysPhone, sau.sys_address sysAddress, sau.create_time createTime, sau.sys_type sysType, sau.idcardno, sau.sys_sex sysSex, sau.sys_age sysAge,sau.class_id classId,sau.school_id schoolId,ts.school_name as schoolName,tc.class_name as className " +
                "from " +
                    "sys_app_user sau",
        "        left join wisdomlessons.t_school ts on sau.school_id = ts.id",
        "        left join wisdomlessons.t_class tc on sau.class_id = tc.id",
            "    <where>",
            "       <if test=\"sysPhone != null  and sysPhone != '' \"> and sau.sys_phone like \"%${sysPhone}%\" </if>",
            "       <if test=\"schoolId != null  and schoolId != '' \"> and sau.school_id = #{schoolId}</if>",
            "    </where>",
            " order by sau.create_time desc ",
            "</script>"
    })
    List<SysAppUser> selectAppUserList(SysAppUser appUser);


    @Select({
            "<script>",
            "  SELECT " +
                    "sau.id, sau.sys_relname sysRelname, sau.sys_ico sysIco, sau.sys_state sysState, sau.sys_phone sysPhone, sau.sys_address sysAddress, sau.create_time createTime, sau.sys_type sysType, sau.idcardno, sau.sys_sex sysSex, sau.sys_age sysAge,sau.class_id classId,sau.school_id schoolId, ts.school_name as schoolName,tc.class_name as className " +
                    "from " +
                    "sys_app_user sau",
            "        left join wisdomlessons.t_school ts on sau.school_id = ts.id",
            "        left join wisdomlessons.t_class tc on sau.class_id = tc.id",
            "    <where>",
            "       <if test=\"id != null  and id != '' \"> and sau.id = #{id}</if>",
            "    </where>",
            "</script>"
    })
    SysAppUser selectOneAppUser(SysAppUser appUser);

}
